<template>
	<view class="home">
		<view class="home-plate-1" v-if="is_token == true">
			<image class="home-logo" src="../../static/home-logo.png" mode=""></image>
			<navigator url="../common/search/search" open-type="navigate" hover-class="none">
				<view class="sousuo">
					<image src="../../static/ic_search.png" mode="widthFix"></image>
					<input type="text" value="" placeholder="看分类,搜商品" />
				</view>
			</navigator>
			<navigator url="../common/cart/cart" hover-class="none" open-type="navigate">
				<image src="../../static/ic_buy.png" class="ic-buy" mode=""></image>
			</navigator>
		</view>
		<view class="home-plate-1" v-else @click="goLogin">
			<image class="home-logo" src="../../static/home-logo.png" mode=""></image>
			<view class="sousuo">
				<image src="../../static/ic_search.png" mode="widthFix"></image>
				<input type="text" value="" placeholder="看分类,搜商品" />
			</view>
			<image src="../../static/ic_buy.png" class="ic-buy" mode=""></image>
		</view>
		<view class="home-plate-2">
			<u-swiper :list="list" height="412" name="img"></u-swiper>
		</view>
		<view class="home-plate-3">
			<navigator url="../common/IM/IM" open-type="navigate" hover-class="none">
				<image :src="jn_banner" mode=""></image>
			</navigator>
		</view>
		<view class="home-plate-4">
			<view class="item" v-for="(item,index) in classData" :key="index" @click="goPage(index)">
				<image :src="item.picture" mode=""></image>
				<text>{{item.pic_name}}</text>
			</view>
		</view>
		<view class="home-plate-5">
			<image :src="item.picture" mode="widthFix" v-for="(item,index) in daTuData" :key="index"></image>
			<view class="item">
				<view class="item-text">
					累计鉴定
					<text>{{jdNum}}</text>
					件
				</view>
				<view class="geduan">

				</view>
				<view class="item-text">
					累计客户
					<text>{{pelNum}}</text>
					人
				</view>
			</view>
		</view>
		<view class="home-plate-6">
			<view class="item" v-for="(item,index) in tagData" :key="index">
				<u-icon name="checkmark-circle" color="#D1AA56" size="25"></u-icon>
				<text>{{item.info}}</text>
			</view>
		</view>
		<view class="home-plate-7" v-if="is_token == true">
			<navigator url="../appraisal/appraisal" open-type="switchTab">
				<view class="left-btn btn-7">
					立即鉴定
				</view>
			</navigator>
			<navigator url="../appraisal/demand/demand" open-type="navigate" hover-class="none">
				<view class="right-btn btn-7">
					证书查询
				</view>
			</navigator>
		</view>
		<view class="home-plate-7" v-else @click="goLogin">
			<view class="left-btn btn-7">
				立即鉴定
			</view>
			<view class="right-btn btn-7">
				证书查询
			</view>
		</view>
		<view class="home-plate-8">
			<text>热门直播</text>
			<navigator url="../live/live" open-type="switchTab">
				<button type="default" class="border-btn">更多</button>
			</navigator>
		</view>
		<view class="home-plate-10">
			<view class="item"  v-for="(item,index) in liveData" :key="index" @click.stop="goLiveRoom(item.live_program_id,item.live_status,item.shielding)">
				<view class="item-top">
					<view class="left">
						<image src="../../static/ic_live_be_about.png" mode="widthFix"></image>
						<text v-if="item.live_status == 1">即将直播</text>
						<text v-if="item.live_status == 2">直播中</text>
						<text v-if="item.live_status == 3">暂停中</text>
						<text v-if="item.live_status == 4">回放中</text>
					</view>
					<view class="right">
						观看人数{{item.views_number}}人
					</view>
				</view>
				<view class="item-btm">
					<view class="top"  @click.stop="onLike(index,item)">
						<u-icon name="thumb-up-fill" :color="activeIndex == index?'#D1AA56':'#fff'" size="38"></u-icon>
						<text>{{item.like_num}}</text>
					</view>
					<view class="btm">
						<u-icon name="chat" color="#fff" size="38"></u-icon>
						<text>{{item.comment_num}}</text>
					</view>
				</view>
				<view class="bottom-bg">
					<image :src="item.live_head_pic"></image>
				</view>
			</view>
		</view>
		<image style="position: fixed;bottom: 60upx;right: 30upx;width: 100upx;z-index: 1000000;" :src="service_data.link"  @click="goIM(service_data.service_im_account)" mode="widthFix"></image>
	</view>
</template>

<script>
	import IM from '@/static/js/IM.js'
	export default {
		data() {
			return {
				list: [],
				classData: [],
				daTuData: [],
				jdNum: '',
				pelNum: '',
				tagData: [],
				liveData: [],
				page: 1,
				service_data: '',
				is_token: false,
				jn_banner: 'https://fei.feicuikuang.com/h5/img/666.png',
				activeIndex:Number
			}
		},
		onPullDownRefresh() {
			this.getBanner()
			this.getClassIco()
			this.getPicImg()
			this.getNumData()
			this.getTag()
			this.getPelNumData()
			this.getLiveListData()
			this.getHomeServiceId()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1400)
		},
		created() {
			this.getBanner()
			this.getClassIco()
			this.getPicImg()
			this.getNumData()
			this.getTag()
			this.getPelNumData()
		},
		onShow() {
			this.getLiveListData()
			this.getHomeServiceId()
			IM.onMessage()
			IM.onTab()
		},
		methods: {
			// 去登陆
			goLogin() {
				uni.showModal({
					content: '宝贝都为珍惜孤品，为了保障您的购买体验和资金安全，系统需要您的授权，所有的信息都会保密',
					confirmText: '去授权',
					confirmColor: '#D1AA56',
					success: (res) => {
						if (res.confirm) {
							uni.switchTab({
								url: '../mine/mine'
							})
						}
					}
				})
			},
			// 前往IM页面
			goIM(id) {
				uni.navigateTo({
					url: '../common/IM/IM?id=' + id
				})
			},
			// 请求首页客服ID
			getHomeServiceId() {
				uni.request({
					url: 'https://fei.feicuikuang.com/index.php/app/live/getHomeService',
					method: 'POST',
					data: {

					},
					header: {
						"token": uni.getStorageSync('token')
					},
					success: (res) => {
						if (res.data.status == 200) {
							this.service_data = res.data.data
							uni.setStorageSync('go_login', 2)
							this.is_token = true
						} else if (res.data.status == 100) {
							uni.setStorageSync('go_login', 1)
							this.is_token = false
						}
					}
				})
			},
			//请求直播间列表
			getLiveListData() {
				uni.request({
					url: this.$Url + '/index.php/app/live/liveList',
					method: 'POST',
					data: {
						p: this.page,
						list_type: 1,
						huifang_type: 2
					},
					header: {
						"token": uni.getStorageSync('token')
					},
					success: (res) => {
						if (res.data.status == 200) {
							this.liveData = res.data.data.live_program_list
						}
					}
				})
			},
			//跳转到直播间
			goLiveRoom(id, num, lahei) {
				if (lahei == 1) {
					if (num == 2) {
						uni.navigateTo({
							url: 'liveRoom?id=' + id
						})
					} else {
						uni.showToast({
							title: '直播还未开始哦~',
							icon: 'none',
							duration: 1200
						})
					}
				} else {
					uni.showToast({
						title: '已被主播拉黑',
						icon: 'none',
						duration: 1200
					})
				}
			},
			//跳转页面
			goPage(index) {
				if (index == 0) {
					uni.switchTab({
						url: '../live/live'
					})
				}
				if (index == 1) {
					uni.navigateTo({
						url: '../common/shop/shop'
					})
				}
				if (index == 2) {
					if (this.is_token == true) {
						uni.navigateTo({
							url: 'video/video'
						})
					} else {
						this.goLogin()
					}

				}
				if (index == 3) {
					uni.switchTab({
						url: '../appraisal/appraisal'
					})
				}
			},
			//请求banner
			getBanner() {
				uni.request({
					url: this.$Url + '/index.php/app/Banner/bannerList',
					method: 'POST',
					data: {
						banner_type: 3
					},
					header: {
						"token": uni.getStorageSync('token')
					},
					success: (res) => {
						this.list = res.data.data
					}
				})
			},
			//请求首页分类图标
			getClassIco() {
				uni.request({
					url: this.$Url + '/index.php/app/Banner/navigationPic',
					method: 'POST',
					data: {
						pic_type: 1
					},
					header: {
						"token": uni.getStorageSync('token')
					},
					success: (res) => {
						this.classData = res.data.data
					}
				})
			},
			//请求首页大图片
			getPicImg() {
				uni.request({
					url: this.$Url + '/index.php/app/Banner/navigationPic',
					method: 'POST',
					data: {
						pic_type: 5
					},
					header: {
						"token": uni.getStorageSync('token')
					},
					success: (res) => {
						this.daTuData = res.data.data
					}
				})
			},
			//请求鉴定数
			getNumData() {
				uni.request({
					url: this.$Url + '/index.php/app/Authentication/authenNum',
					method: 'POST',
					data: {
						type: 2
					},
					header: {
						"token": uni.getStorageSync('token')
					},
					success: (res) => {
						this.jdNum = res.data.data
					}
				})
			},
			//累计客户数量
			getPelNumData() {
				uni.request({
					url: this.$Url + '/index.php/app/Authentication/authenNum',
					method: 'POST',
					data: {
						type: 3
					},
					header: {
						"token": uni.getStorageSync('token')
					},
					success: (res) => {
						this.pelNum = res.data.data
					}
				})
			},
			//请求tag标签
			getTag() {
				uni.request({
					url: this.$Url + '/index.php/app/Banner/authentication',
					method: 'POST',
					data: {},
					header: {
						"token": uni.getStorageSync('token')
					},
					success: (res) => {
						this.tagData = res.data.data
					}
				})
			},
			//点赞
			onLike(index,item) {
				uni.request({
				    url:this.$Url +'/index.php/App/Live/changeLikeNum',
				    method:'POST',
				    data:{
						live_program_id:item.live_program_id
				    },
					header:{
						"token":uni.getStorageSync('token')
					},
				    success: (res) => {
						this.activeIndex = index
						return item.like_num++
				    }
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.home {
		width: 100vw;
		height: 100vh;
		background-color: #fafafa;

		.home-plate-1 {
			height: 95upx;
			width: 100vw;
			display: flex;
			align-items: center;
			justify-content: center;

			.home-logo {
				width: 148upx;
				height: 35upx;
				margin-right: 28upx;
			}

			.sousuo {
				width: 450upx;
				height: 60upx;
				border: 1px solid #666;
				border-radius: 35upx;
				display: flex;
				align-items: center;

				image {
					width: 30upx;
					height: 30upx;
					margin-left: 25upx;
					margin-right: 25upx;
				}

				input {
					font-size: 28upx;
					color: #f0f0f0;
				}
			}

			.ic-buy {
				width: 50upx;
				height: 50upx;
				margin-left: 22upx;
			}
		}

		.home-plate-2 {
			width: 100vw;
			height: 412upx;
		}

		.home-plate-3 {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 10upx;

			image {
				width: 712upx;
				height: 148upx;
			}
		}

		.home-plate-4 {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 50upx;
			height: 207upx;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				image {
					width: 103upx;
					height: 103upx;
					margin-bottom: 12upx;
				}

				text {
					font-size: 24upx;
					color: #333;
				}
			}
		}

		.home-plate-5 {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			width: 710upx;
			border-radius: 20upx;
			margin: 0 auto;
			box-shadow: 0px 3upx 10upx 6upx rgba(0, 0, 0, 0.3);

			image {
				width: 710upx;
				border-top-right-radius: 20upx;
				border-top-left-radius: 20upx;
			}

			.item {
				width: 710upx;
				height: 90upx;
				border-bottom-right-radius: 20upx;
				border-bottom-left-radius: 20upx;
				background-color: #fff;
				display: flex;
				align-items: center;
				justify-content: center;

				.item-text {
					font-size: 30upx;
					color: #333;

					text {
						color: #dbb869;
					}
				}

				.geduan {
					width: 4upx;
					height: 23upx;
					background-color: #333;
					margin: 0 20upx;
				}
			}
		}

		.home-plate-6 {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 45upx;
			height: 60upx;

			.item {
				display: flex;
				align-items: center;

				image {
					width: 25upx;
					margin-right: 15upx;
				}

				text {
					font-size: 28upx;
					color: #333;
				}
			}
		}

		.home-plate-7 {
			display: flex;
			align-items: center;
			justify-content: center;

			.btn-7 {
				width: 356upx;
				height: 72upx;
				font-size: 32upx;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.left-btn {
				background-color: #dbb869;
				border-top-left-radius: 40upx;
				border-bottom-left-radius: 40upx;
				color: #fff;
			}

			.right-btn {
				color: #dbb869;
				border-top-right-radius: 40upx;
				border-bottom-right-radius: 40upx;
				background-color: #434343;
			}
		}

		.home-plate-8 {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 20upx;
			height: 130upx;
			width: 100%;

			text {
				font-size: 38upx;
				font-weight: 600;
			}

			button {
				width: 125upx;
				height: 50upx;
				font-size: 26upx;
				color: #d2a440;
				margin: 0;
				background-color: #fff;
			}
		}

		.home-plate-10 {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			.item{
				width: 355rpx;
				height: 418rpx;
				border-radius: 30rpx;
				background-size: 100% 100%;
				position: relative;
				padding: 1rpx;
				margin: 10rpx;
				.bottom-bg{
					position: absolute;
					top: 0rpx;
					bottom: 0rpx;
					width: 355rpx;
					height: 418rpx;
					border-radius: 30rpx;
					z-index: -1;
					image{
						width: 355rpx;
						height: 418rpx;
						border-radius: 30rpx;
					}
				}
				.item-top{
					display: flex;
					align-items: center;
					margin: 20rpx 0 0 20rpx;
					.left{
						box-sizing: border-box;
						width: 150rpx;
						height: 50rpx;
						border-top-left-radius: 40rpx;
						border-bottom-left-radius: 40rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background-color: $zhuti-color;
						image{
							width: 32rpx;
							height: 32rpx;
						}
						text{
							font-size: 22rpx;
							margin-left: 8rpx;
							color: #fff;
						}
					}
					.right{
						box-sizing: border-box;
						width: 150rpx;
						height: 50rpx;
						border-top-right-radius: 40rpx;
						border-bottom-right-radius: 40rpx;
						background-color: rgba(255,255,255,0.2);
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 22rpx;
						color: #fff;
					}
				}
				.item-btm{
					display: flex;
					flex-direction: column;
					justify-content: flex-end;
					align-items: flex-end;
					padding-right: 20rpx;
					margin-top: 95rpx;
					.top{
						display: flex;
						align-items: center;
						justify-content: center;
						flex-direction: column;
						margin-bottom: 20rpx;
						text{
							font-size: 22rpx;
							color: #fff;
						}
					}
					.btm{
						display: flex;
						align-items: center;
						justify-content: center;
						flex-direction: column;
						text{
							font-size: 22rpx;
							color: #fff;
						}
					}
				}
			}
		}

	}
</style>
